<template>
    <div class="icons">
        <swiper :options="swiperOption" >
            <swiper-slide v-for="(page,index) of pages" :key="index">
                <div class="icon" v-for="item of page" :key="item.id">
                    <div class="icon-img">
                        <img class="icon-img-content" :src="item.iconUrl" alt="">
                    </div>
                    <p class="icon-text">{{item.desc}}</p>
                </div>
            </swiper-slide>
        </swiper>
    </div>
</template>

<script>
export default {
  name: 'HomeIcons',
  props: {
    iconlist: Array
  },
  data () {
    return {
      swiperOption: {
        autoPlay: false
      }
    }
  },
  computed: {
    pages () {
      var pages = []
      this.iconlist.forEach(function (item, index) {
        var page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    }
  }
}
</script>

<style lang="stylus" scoped>
@import '~styles/varibles.styl'
@import '~styles/mixin.styl'
  .icons >>> .swiper-container
    height 0
    padding-bottom 50%
    padding-top: .2rem;
  .icons
    background $bgColorFff
    .icon
      position relative
      float left
      width 25%
      overflow hidden
      height 1.5rem
      .icon-img
          margin 0 auto
          width 1.1rem
          height 1.1rem
          box-sizing border-box
          padding-top .1rem
          .icon-img-content
              display block
              width 1.1rem
              height 1.1rem
              margin 0 auto
      .icon-text
          position absolute
          left 0
          right 0
          bottom 0
          font-size 0.28rem
          text-align center
          color $darkTextClor
          ellipsis()
</style>
